package io;

import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;

public class IODemo6 {
    // 使用字节流来读取文件
    public static void main(String[] args) throws IOException {
        InputStream inputStream = new FileInputStream("D:/Desktop/gdyg.jpg");

//        while (true) {
//            int b = inputStream.read();
//            if (b == -1) {
//                break;
//            }
//
//            System.out.printf("%x\n", (byte)b);
//        }

        while (true) {
            byte[] buffer = new byte[1024];
            int len = inputStream.read(buffer);
            System.out.println("len:" + len);
            if (len == -1) {
                break;
            }

            // 读取的结果放到 byte 数组里
            for (int i = 0; i < len; i++) {
                System.out.printf("%x\n", buffer[i]);
            }
        }

        inputStream.close();
    }
}
